package br.com.transitojp.dao;

import java.io.Serializable;

import org.hibernate.Query;
import org.hibernate.Session;

import br.com.transitojp.model.User;

public class DaoUser extends GenericDAOHibernate<User, Serializable> {

	public DaoUser(Session session) {
		super(session);
	}

	public User validateLogin(String login, String password) {

		Session s = this.getSession();
		Query q = s.createQuery("SELECT u FROM User u WHERE u.login=:login and u.password=:password");

		q.setParameter("login", login);
		q.setParameter("password", password);

		User user = (User) q.uniqueResult();

		return user;

	}
	
	public User findByLogin(String login){
		Query q = this.getSession().createQuery("SELECT u FROM User u WHERE u.login=:login"); 			
		q.setParameter("login", login);
		User user = (User)q.uniqueResult();
		return user;
	}
}
